<%@ page import="com.bdqn.t382.lx.pojo.SysUser" %><%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2025/2/28
  Time: 19:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<%--<%--%>
<%--    SysUser user = (SysUser) session.getAttribute("user");--%>
<%--    if (user == null) {--%>
<%--        response.sendRedirect("erro.jsp");--%>
<%--    }--%>
<%--%>--%>
<div align="center">
    <form action="formAdd" method="post">
        <table>
            <tr align="center">
                <td colspan="3"><h3>新增图书信息</h3></td>
            </tr>
            <tr>
                <td>图书名称：</td>
                <td><input type="text" name="b_name" id="b_name"></td>
            </tr>
            <tr>
                <td>图书作者：</td>
                <td><input type="text" name="b_author" id="b_author"></td>
                <td></td>
            </tr>
            <tr>
                <td>购买日期：</td>
                <td><input type="date" name="b_time" id="b_time"></td>
                <td>yyyy-MM-dd格式</td>
            </tr>
            <tr>
                <td>图书类别：</td>
                <td>
                    <select name="b_type" id="b_type">
                        <option value="0">请选择所属分类</option>
                        <option value="1">计算机/软件</option>
                        <option value="2">小说/文摘</option>
                        <option value="3">杂项</option>
                    </select>
                </td>
                <td></td>
            </tr>
            <tr align="center">
                <td colspan="3"><input type="submit" value="增加图书"></td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>
<script type="text/javascript">
    $(document).ready(function () {
        $("form").submit(function (e) {
            var b_name = $("#b_name").val().trim();
            var b_author = $("#b_author").val().trim();
            var b_time = $("#b_time").val().trim();
            var b_type = $("#b_type").val().trim();
            var dateRegex = /^\d{4}-\d{2}-\d{2}$/;
            if (b_name == ""||b_author == "") {
                alert("图书名称和图书作者不能为空！");
                return false;
            }else if (!dateRegex.test(b_time)) {
                alert("日期格式不正确！");
                return false;
            }else if (b_type==0||b_type=="") {
                alert("请选择图书分类！");
                return false;
            }else {
                alert("添加图书成功！")
                return true;
            }

        });
    });
</script>